﻿//
// 获取数据方法
//
function fnGetData(entity, condition, order, IsDesc, functionId) {
    
    var _Data = null;
    $.ajax({
        type: "GET",
        url: "/Extend/AjaxData/DataTableJsonList.aspx",
        data: { r: Math.random(),  pagesize: 200, entity: entity, condition: condition, order: (typeof (order) == "undefined") ? "" : order, desc: (typeof(IsDesc) == "undefined" ? "" : IsDesc), functionid: typeof (functionId) == "undefined" ? "" : functionId },
        async: false,
        success: function (data) {

            if (data == '{"total":0,"rows":}') {
                _Data = null;
            }
            else {
                _Data = eval("(" + data + ")");
            }
        },
        error: function (e) {
            return;
        }
    }
    );
    return _Data;
}

function fnNotAsyncGetData(entity, condition, order, IsDesc, functionId) {
    var defer = $.Deferred();        
    //var _Data = null;
    $.ajax({
        type: "GET",
        url: "/Extend/AjaxData/DataTableJsonList.aspx",
        data: { r: Math.random(), pagesize: 200, entity: entity, condition: condition, order: (typeof (order) == "undefined") ? "" : order, desc: (typeof (IsDesc) == "undefined" ? "" : IsDesc), functionid: typeof (functionId) == "undefined" ? "" : functionId },
        success: function (data) {
            defer.resolve(data);
        },
        error: function (e) {
            return;
        }
    }
    );
    return defer.promise();
}

function fnGetAsyncData(entity, condition, order, IsDesc, functionId,callback) {
    //debugger
    var _Data = null;
    $.ajax({
        type: "GET",
        url: "/Extend/AjaxData/DataTableJsonList.aspx",
        data: { r: Math.random(), pagesize: 200, entity: entity, condition: condition, order: (typeof (order) == "undefined") ? "" : order, desc: (typeof (IsDesc) == "undefined" ? "" : IsDesc), functionid: typeof (functionId) == "undefined" ? "" : functionId },
        success: function (data) {
            //debugger
            if (data == '{"total":0,"rows":}') {
                _Data = null;
            }
            else {
                _Data = eval("(" + data + ")");
            }
            if (typeof (callback) == "function") {
                if (_Data != null) {
                    callback(_Data.rows);
                }
                else {
                    callback("not data");
                }
            }
        },
        error: function (e) {
            return;
        }
    }
    );
   // return _Data;
} 


/* 请求Ajax 带返回值
--------------------------------------------------*/
function getAjax(url, parm, callBack) {
    $.ajax({
        type: 'post',
        dataType: "text",
        //async: false,
        url: url,
        data: parm,
        cache: false,
        async: false,
        success: function (data) {
            if (callBack) {
                callBack(data);
            }
        }
    });
}

/// ---------------------
/// 获取加班数据
/// ---------------------
function fnGetOTData() {

}

///------------------------
///获得调休数据
///------------------------
function fnGetOverTimeLeaveData(EmpCode) {

    var entity = fnGetData("V_wkRemTOvertimeLeave", "EmployeeCode='" + EmpCode + "'");
    if (entity != null) {
        return entity.rows[0];
    }
    return null;
}
///
/// 历史调薪记录
///
function fnGetSalaryRecords(EmpCode) {
    var entity = fnGetData("V_salBaseSalary", "EmployeeCode='" + EmpCode + "'");
    if (entity != null) {
        return entity.rows;
    }
    return null;
}

/// ---------------------
/// 历史调薪记录
/// ---------------------
function fnGetSalaryRecordByID(empID) {
    var entity = fnGetData("V_salBaseSalary", "EmployeeID='" + empID + "'", "EffectDate", "Yes");
    if (entity != null) {
        return entity.rows;
    }
    return null;
}

function fnGetSalaryHistoryByID(empID) {
    var entity = fnGetData("V_salBaseSalary", "EmployeeID='" + empID + "'", "EffectDate", "Yes");
    if (entity != null) {
        return entity.rows;
    }
    return null;
}

/// ---------------------
/// 获得调休数据
/// ---------------------
function fnGetOverTimeLeaveDataByID(empID) {
    var entity = fnGetData("V_wkRemTOvertimeLeave", "EmployeeID='" + EmpCode + "'");
    if (entity != null) {
        return entity.rows[0];
    }
    return null;
}


/// --------------------------------
/// 打卡数据
/// --------------------------------
function fnGetCardData(EmpCode, Date) {
    var entity = fnGetData("V_salBaseSalary", "EmployeeCode='" + EmpCode + "'");
    if (entity != null) {
        return entity.rows;
    }
    return null;
}

/// --------------------------------
/// 获取人员入职日期
/// --------------------------------
function fnGetEmployeeJoinDate(EmpCode) {
    var entity = fnGetEmployee(EmpCode);
    if (entity == null) {
        return null;
    }
    else {
        return entity.JoinDate;
    }
}
function fnGetEmployeeJoinDateByID(empID) {
    var entity = fnGetEmployeeByID(empID);
    if (entity == null) {
        return null;
    }
    else {
        return entity.JoinDate;
    }
}

/// -----------------------------
/// 获取人员信息
/// -----------------------------
function fnGetEmployee(EmpCode) {
    var entity = fnGetData("V_hrEmployee", "EmployeeCode='" + EmpCode + "'");
    if (entity != null) {
        return entity.rows[0];
    }
    return null;
}

function fnGetEmployeeByID(empID) {
    //debugger
    var entity = fnGetData("V_hrEmployee", "ID='" + empID + "'");
    if (entity != null) {
        return entity.rows[0].JoinDate;
    }
    return null;
}


//------------
//获取流程申请者
//------------
function fnGetWFAppOpr(workflowInsID) {
    var entity = fnGetData("V_WFApplicationOpr", "WorkFlowInstanceId='" + workflowInsID + "'");
    if (entity != null) {
        return entity.rows[0].EmpID;
    }
    return null;
}


//---------------
// 获取个人加班信息
//---------------
function fnGetOTData(empID) {
    var entity = fnGetData("V_wkOTLevaeTotal", "EmployeeID='" + empID + "'");
    if (entity != null) {
        return entity.rows[0];
    }
    return null;
}

//---------------
// 获取个人年假信息
//---------------
function fnGetEmpYearVacationBPM(empID) {
    //alert(empID);
    var entity = fnGetData("V_wkEmployeeYearVacation_BPM", "EmployeeID='" + empID + "'");
    if (entity != null) {
        return entity.rows[0];
    }
    return null;
}

//----------------
// 申请人的员工ID
//----------------
function fnGetWFEmployeeID() {
    var employeeID = "";
    if (getPar1("id") == "") {
        employeeID = userPropertyValues[0].EmployeeID;
    }
    else {
        employeeID = fnGetWFAppOpr(instance[0].WorkFlowInsId);
    }
    return employeeID;
}


//-------------------- 
// 获取个人 加班 信息
//--------------------
function fnGetEmployeeOTData() {
    var employeeID = fnGetWFEmployeeID();
    return fnGetOTData(employeeID);
}


$(document).ready(function () {
    if (typeof (getPar1) == "function") {
        if (getPar1("id") == "") {
            if ($("#ruzhishijian").length > 0) {
                //alert(fnGetEmployeeByID(userPropertyValues[0].EmployeeID));
                $("#ruzhishijian").val(fnGetEmployeeByID(userPropertyValues[0].EmployeeID));
            }
            if ($("#ruzhiriqi").length > 0) {
                //alert(fnGetEmployeeByID(userPropertyValues[0].EmployeeID));
                $("#ruzhiriqi").val(fnGetEmployeeByID(userPropertyValues[0].EmployeeID));
            }
        }
    }
});
